<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="author" content="esy">
    
    <meta name="description" content="esy">
    
    
    
    
    
    
    <title>分类模型基于交叉验证进行评估 | ESY</title>
    <link href="https://esyyes.github.io" rel="prefetch" />

    
<link rel="stylesheet" href="/css/bootstrap.min.css">
<link rel="stylesheet" href="/css/aos.css">
<link rel="stylesheet" href="/css/style.css">

    
<script src="/js/jquery.min.js"></script>

    
<script src="/js/bootstrap.min.js"></script>

    
<script src="/js/aos.js"></script>

    
<script src="/js/highslide/highslide-full.min.js"></script>

    
<link rel="stylesheet" href="/js/highslide/highslide.css">

    <style type="text/css">
        @media (max-width: 768px) {
            body {
                background-color: #f0f0f0;
                background: url('/imgs/xsbg.gif');
                background-attachment: fixed;
            }
        }
    </style>
    
    <!--<script type="text/javascript">
      if (document.images) {
        var avatar = new Image();
        avatar.src = '/imgs/avatar.jpg'
        var previews = 'preview1.jpg,preview2.jpg,preview3.jpg,preview4.jpg'.split(',')
        var previewsPreLoad = []
        for(var i = 0; i < length; i++) {
          previewsPreLoad.push(new Image())
          previewsPreLoad[previewsPreLoad.length - 1].src = '/imgs/preview' + previews[i]
        }
      }
    </script>-->
<meta name="generator" content="Hexo 5.2.0"></head>
<body>
    <!-- 背景轮播图功能 -->
    <section class="hidden-xs">
    <ul class="cb-slideshow">
        <li><span>天若</span></li>
        <li><span>有情</span></li>
        <li><span>天亦老</span></li>
        <li><span>我为</span></li>
        <li><span>长者</span></li>
        <li><span>续一秒</span></li>
    </ul>
</section>
    <!-- 欧尼酱功能, 谁用谁知道 -->
    
    <div class="gal-menu gal-dropdown">
    <div class="circle" id="gal">
        <div class="ring">
            <a href="https://esyyes.github.io" class="menuItem" style="left: 50%; top: 15%;">首页</a>
            
            <a class="menuItem" style="left: 80.3109%; top: 32.5%;">下一页</a>
            
            <a href="/archives" class="menuItem" style="left: 80.3109%; top: 67.5%;">归档</a>
            <a href="/about" class="menuItem" style="left: 50%; top: 85%;">关于</a>
            <a href="/message" class="menuItem" style="left: 19.6891%; top: 67.5%;">留言板</a>

            
            <a class="menuItem" style="left: 19.6891%; top: 32.5%;">上一页</a>
            
        </div>
        <audio id="audio" src="/imgs/oni.mp3"></audio>
    </div>
</div>
    
    <header class="navbar navbar-inverse" id="gal-header">
    <div class="container">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle collapsed"
                    data-toggle="collapse" data-target=".bs-navbar-collapse"
                    aria-expanded="false">
                <span class="fa fa-lg fa-reorder"></span>
            </button>
            <a href="https://esyyes.github.io">
                
                <style>
                    #gal-header .navbar-brand {
                        height: 54px;
                        line-height: 24px;
                        font-size: 28px;
                        opacity: 1;
                        background-color: rgba(0,0,0,0);
                        text-shadow: 0 0 5px #fff,0 0 10px #fff,0 0 15px #fff,0 0 20px #228DFF,0 0 35px #228DFF,0 0 40px #228DFF,0 0 50px #228DFF,0 0 75px #228DFF;
                    }
                </style>
                <!-- 这里使用文字(navbar_text or config.title) -->
                <div class="navbar-brand">ESY</div>
                
            </a>
        </div>
        <div class="collapse navbar-collapse bs-navbar-collapse">
            <ul class="nav navbar-nav" id="menu-gal">
                
                
                <li class="">
                    <a href="/">
                        <i class="fa fa-home"></i>首页
                    </a>
                </li>
                
                
                
                <li class="">
                    <a href="/archives">
                        <i class="fa fa-archive"></i>归档
                    </a>
                </li>
                
                
                
                
                <li class="dropdown">
                    <!-- TODO 添加hover dropdown效果 -->
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown"
                       aria-haspopup="true" aria-expanded="false" data-hover="dropdown">
                        <i class="fa fa-list"></i>分类
                    </a>
                    <ul class="dropdown-menu">
                        
                        
                        <li>
                            <a href="/categories/py-study/">py_study</a>
                        </li>
                        
                        <li>
                            <a href="/categories/nlp/">nlp</a>
                        </li>
                        
                        <li>
                            <a href="/categories/Graduation-work/">Graduation work</a>
                        </li>
                        
                        <li>
                            <a href="/categories/work/">work</a>
                        </li>
                        
                        <li>
                            <a href="/categories/hexo/">hexo</a>
                        </li>
                        
                        <li>
                            <a href="/categories/hexo%E5%AE%8C%E5%96%84/">-hexo完善</a>
                        </li>
                        
                        
                        <li>
                            <a href="/categories">...</a>
                        </li>
                        
                        
                    </ul>
                </li>
                
                
                
                
                
                <li class="dropdown">
                    <!-- TODO 添加hover dropdown效果 -->
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown"
                       aria-haspopup="true" aria-expanded="false" data-hover="dropdown">
                        <i class="fa fa-tags"></i>标签
                    </a>
                    <ul class="dropdown-menu">
                        
                        
                        <li>
                            <a href="/tags/py-study/">py_study</a>
                        </li>
                        
                        <li>
                            <a href="/tags/nlp/">nlp</a>
                        </li>
                        
                        <li>
                            <a href="/tags/Graduation-work/">Graduation work</a>
                        </li>
                        
                        <li>
                            <a href="/tags/work/">work</a>
                        </li>
                        
                        <li>
                            <a href="/tags/hexo/">hexo</a>
                        </li>
                        
                        <li>
                            <a href="/tags/%E4%B8%AA%E4%BA%BA%E5%8D%9A%E5%AE%A2%E6%90%AD%E5%BB%BA/">-个人博客搭建</a>
                        </li>
                        
                        
                        <li>
                            <a href="/tags">...</a>
                        </li>
                        
                        
                    </ul>
                </li>
                
                
                
                
                <li class="">
                    <a href="/about">
                        <i class="fa fa-user"></i>关于我
                    </a>
                </li>
                
                
            </ul>
        </div>
    </div>
</header>
    <div id="gal-body">
        <div class="container">
            <div class="row">
                <div class="col-md-8 gal-right" id="mainstay">
                    
<article class="article well article-body" id="article">
    <div class="breadcrumb">
        <i class="fa fa-home"></i>
        <a href="https://esyyes.github.io">ESY</a>
        >
        <span>分类模型基于交叉验证进行评估</span>
    </div>
    <!-- 大型设备详细文章 -->
    <div class="hidden-xs">
        <div class="title-article">
            <h1>
                <a href="/2020/08/31/python%20work/%E5%88%86%E7%B1%BB%E6%A8%A1%E5%9E%8B%E5%9F%BA%E4%BA%8E%E4%BA%A4%E5%8F%89%E9%AA%8C%E8%AF%81%E8%BF%9B%E8%A1%8C%E8%AF%84%E4%BC%B0/">分类模型基于交叉验证进行评估</a>
            </h1>
        </div>
        <div class="tag-article">
            
            <span class="label label-gal">
                <i class="fa fa-tags"></i>
                
                <a href="/tags/work/">work</a>
                
            </span>
            
            <span class="label label-gal">
                <i class="fa fa-calendar"></i> 2020-08-31
            </span>
            
        </div>
    </div>
    <!-- 小型设备详细文章 -->
    <div class="visible-xs">
        <center>
            <div class="title-article">
                <h4>
                    <a href="/2020/08/31/python%20work/%E5%88%86%E7%B1%BB%E6%A8%A1%E5%9E%8B%E5%9F%BA%E4%BA%8E%E4%BA%A4%E5%8F%89%E9%AA%8C%E8%AF%81%E8%BF%9B%E8%A1%8C%E8%AF%84%E4%BC%B0/">分类模型基于交叉验证进行评估</a>
                </h4>
            </div>
            <p>
                <i class="fa fa-calendar"></i> 2020-08-31
            </p>
            <p>
                
                <i class="fa fa-tags"></i>
                
                <a href="/tags/work/">work</a>
                
                
                
            </p>
        </center>
    </div>
    <div class="content-article">
        <h1 id="分类模型基于交叉验证进行评估"><a href="#分类模型基于交叉验证进行评估" class="headerlink" title="分类模型基于交叉验证进行评估"></a>分类模型基于交叉验证进行评估</h1><p>现在只考虑8个分类模型，因为MLP在sklearn中运行速度太慢，就不进行考虑</p>
<p>对模型加入交叉验证后的精准度，标准差，还有准确率都分别进行评估</p>
<h2 id="库函数"><a href="#库函数" class="headerlink" title="库函数"></a>库函数</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># -*- coding: utf-8 -*-</span></span><br><span class="line"><span class="comment"># @Time     : 2020/8/31</span></span><br><span class="line"><span class="comment"># @Author   : esy</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> numpy <span class="keyword">as</span> np</span><br><span class="line"><span class="keyword">from</span> sklearn.linear_model <span class="keyword">import</span> LogisticRegression</span><br><span class="line"><span class="keyword">from</span> sklearn.svm <span class="keyword">import</span> LinearSVC, SVC</span><br><span class="line"><span class="keyword">from</span> sklearn.linear_model <span class="keyword">import</span> SGDClassifier</span><br><span class="line"><span class="keyword">from</span> sklearn.tree <span class="keyword">import</span> DecisionTreeClassifier</span><br><span class="line"><span class="keyword">from</span> sklearn.neighbors <span class="keyword">import</span> KNeighborsClassifier</span><br><span class="line"><span class="keyword">from</span> sklearn.ensemble <span class="keyword">import</span> RandomForestClassifier, GradientBoostingClassifier</span><br><span class="line"><span class="keyword">from</span> sklearn.metrics <span class="keyword">import</span> precision_score, recall_score, f1_score</span><br><span class="line"><span class="keyword">from</span> sklearn.model_selection <span class="keyword">import</span> cross_val_score, cross_val_predict</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment"># 逻辑回归模型</span></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">run_lr</span>(<span class="params">train_x, train_y</span>):</span></span><br><span class="line">    clf = LogisticRegression()</span><br><span class="line">    clf.fit(train_x, train_y)</span><br><span class="line">    <span class="comment"># 10折交叉验证,获取准确率的均值和标准差</span></span><br><span class="line">    scores = cross_val_score(clf, train_x, train_y, scoring=<span class="string">&#x27;accuracy&#x27;</span>, cv=<span class="number">10</span>)</span><br><span class="line">    mean_score = np.array(scores).mean()</span><br><span class="line">    std_score = np.array(scores).std()</span><br><span class="line">    <span class="comment"># 10折交叉验证,获取预测类别</span></span><br><span class="line">    pre_train = cross_val_predict(clf, train_x, train_y, cv=<span class="number">10</span>)</span><br><span class="line">    <span class="comment"># 获取精准度，召回率还有F1得分</span></span><br><span class="line">    precision = precision_score(train_y, pre_train, average=<span class="string">&#x27;macro&#x27;</span>)</span><br><span class="line">    recall = recall_score(train_y, pre_train, average=<span class="string">&#x27;macro&#x27;</span>)</span><br><span class="line">    F1 = f1_score(train_y, pre_train, average=<span class="string">&#x27;macro&#x27;</span>)</span><br><span class="line">    <span class="keyword">return</span> [mean_score, std_score, precision, recall, F1]</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment"># 线性支持向量机</span></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">run_linearsvc</span>(<span class="params">train_x, train_y</span>):</span></span><br><span class="line">    clf = LinearSVC()</span><br><span class="line">    clf.fit(train_x, train_y)</span><br><span class="line">    <span class="comment"># 10折交叉验证,获取准确率的均值和标准差</span></span><br><span class="line">    scores = cross_val_score(clf, train_x, train_y, scoring=<span class="string">&#x27;accuracy&#x27;</span>, cv=<span class="number">10</span>)</span><br><span class="line">    mean_score = np.array(scores).mean()</span><br><span class="line">    std_score = np.array(scores).std()</span><br><span class="line">    <span class="comment"># 10折交叉验证,获取预测类别</span></span><br><span class="line">    pre_train = cross_val_predict(clf, train_x, train_y, cv=<span class="number">10</span>)</span><br><span class="line">    <span class="comment"># 获取精准度，召回率还有F1得分</span></span><br><span class="line">    precision = precision_score(train_y, pre_train, average=<span class="string">&#x27;macro&#x27;</span>)</span><br><span class="line">    recall = recall_score(train_y, pre_train, average=<span class="string">&#x27;macro&#x27;</span>)</span><br><span class="line">    F1 = f1_score(train_y, pre_train, average=<span class="string">&#x27;macro&#x27;</span>)</span><br><span class="line">    <span class="keyword">return</span> [mean_score, std_score, precision, recall, F1]</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment"># 梯度下降法</span></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">run_sgd</span>(<span class="params">train_x, train_y</span>):</span></span><br><span class="line">    clf = SGDClassifier()</span><br><span class="line">    clf.fit(train_x, train_y)</span><br><span class="line">    <span class="comment"># 10折交叉验证,获取准确率的均值和标准差</span></span><br><span class="line">    scores = cross_val_score(clf, train_x, train_y, scoring=<span class="string">&#x27;accuracy&#x27;</span>, cv=<span class="number">10</span>)</span><br><span class="line">    mean_score = np.array(scores).mean()</span><br><span class="line">    std_score = np.array(scores).std()</span><br><span class="line">    <span class="comment"># 10折交叉验证,获取预测类别</span></span><br><span class="line">    pre_train = cross_val_predict(clf, train_x, train_y, cv=<span class="number">10</span>)</span><br><span class="line">    <span class="comment"># 获取精准度，召回率还有F1得分</span></span><br><span class="line">    precision = precision_score(train_y, pre_train, average=<span class="string">&#x27;macro&#x27;</span>)</span><br><span class="line">    recall = recall_score(train_y, pre_train, average=<span class="string">&#x27;macro&#x27;</span>)</span><br><span class="line">    F1 = f1_score(train_y, pre_train, average=<span class="string">&#x27;macro&#x27;</span>)</span><br><span class="line">    <span class="keyword">return</span> [mean_score, std_score, precision, recall, F1]</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment"># 非线性的支持向量机</span></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">run_svc</span>(<span class="params">train_x, train_y</span>):</span></span><br><span class="line">    clf = SVC()</span><br><span class="line">    clf.fit(train_x, train_y)</span><br><span class="line">    <span class="comment"># 10折交叉验证,获取准确率的均值和标准差</span></span><br><span class="line">    scores = cross_val_score(clf, train_x, train_y, scoring=<span class="string">&#x27;accuracy&#x27;</span>, cv=<span class="number">10</span>)</span><br><span class="line">    mean_score = np.array(scores).mean()</span><br><span class="line">    std_score = np.array(scores).std()</span><br><span class="line">    <span class="comment"># 10折交叉验证,获取预测类别</span></span><br><span class="line">    pre_train = cross_val_predict(clf, train_x, train_y, cv=<span class="number">10</span>)</span><br><span class="line">    <span class="comment"># 获取精准度，召回率还有F1得分</span></span><br><span class="line">    precision = precision_score(train_y, pre_train, average=<span class="string">&#x27;macro&#x27;</span>)</span><br><span class="line">    recall = recall_score(train_y, pre_train, average=<span class="string">&#x27;macro&#x27;</span>)</span><br><span class="line">    F1 = f1_score(train_y, pre_train, average=<span class="string">&#x27;macro&#x27;</span>)</span><br><span class="line">    <span class="keyword">return</span> [mean_score, std_score, precision, recall, F1]</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment"># 决策树</span></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">run_tree</span>(<span class="params">train_x, train_y</span>):</span></span><br><span class="line">    clf = DecisionTreeClassifier()</span><br><span class="line">    clf.fit(train_x, train_y)</span><br><span class="line">    <span class="comment"># 10折交叉验证,获取准确率的均值和标准差</span></span><br><span class="line">    scores = cross_val_score(clf, train_x, train_y, scoring=<span class="string">&#x27;accuracy&#x27;</span>, cv=<span class="number">10</span>)</span><br><span class="line">    mean_score = np.array(scores).mean()</span><br><span class="line">    std_score = np.array(scores).std()</span><br><span class="line">    <span class="comment"># 10折交叉验证,获取预测类别</span></span><br><span class="line">    pre_train = cross_val_predict(clf, train_x, train_y, cv=<span class="number">10</span>)</span><br><span class="line">    <span class="comment"># 获取精准度，召回率还有F1得分</span></span><br><span class="line">    precision = precision_score(train_y, pre_train, average=<span class="string">&#x27;macro&#x27;</span>)</span><br><span class="line">    recall = recall_score(train_y, pre_train, average=<span class="string">&#x27;macro&#x27;</span>)</span><br><span class="line">    F1 = f1_score(train_y, pre_train, average=<span class="string">&#x27;macro&#x27;</span>)</span><br><span class="line">    <span class="keyword">return</span> [mean_score, std_score, precision, recall, F1]</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment"># KNN</span></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">run_knn</span>(<span class="params">train_x, train_y</span>):</span></span><br><span class="line">    clf = KNeighborsClassifier()</span><br><span class="line">    clf.fit(train_x, train_y)</span><br><span class="line">    <span class="comment"># 10折交叉验证,获取准确率的均值和标准差</span></span><br><span class="line">    scores = cross_val_score(clf, train_x, train_y, scoring=<span class="string">&#x27;accuracy&#x27;</span>, cv=<span class="number">10</span>)</span><br><span class="line">    mean_score = np.array(scores).mean()</span><br><span class="line">    std_score = np.array(scores).std()</span><br><span class="line">    <span class="comment"># 10折交叉验证,获取预测类别</span></span><br><span class="line">    pre_train = cross_val_predict(clf, train_x, train_y, cv=<span class="number">10</span>)</span><br><span class="line">    <span class="comment"># 获取精准度，召回率还有F1得分</span></span><br><span class="line">    precision = precision_score(train_y, pre_train, average=<span class="string">&#x27;macro&#x27;</span>)</span><br><span class="line">    recall = recall_score(train_y, pre_train, average=<span class="string">&#x27;macro&#x27;</span>)</span><br><span class="line">    F1 = f1_score(train_y, pre_train, average=<span class="string">&#x27;macro&#x27;</span>)</span><br><span class="line">    <span class="keyword">return</span> [mean_score, std_score, precision, recall, F1]</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment"># 随机森林</span></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">run_rf</span>(<span class="params">train_x, train_y</span>):</span></span><br><span class="line">    clf = RandomForestClassifier()</span><br><span class="line">    clf.fit(train_x, train_y)</span><br><span class="line">    <span class="comment"># 10折交叉验证,获取准确率的均值和标准差</span></span><br><span class="line">    scores = cross_val_score(clf, train_x, train_y, scoring=<span class="string">&#x27;accuracy&#x27;</span>, cv=<span class="number">10</span>)</span><br><span class="line">    mean_score = np.array(scores).mean()</span><br><span class="line">    std_score = np.array(scores).std()</span><br><span class="line">    <span class="comment"># 10折交叉验证,获取预测类别</span></span><br><span class="line">    pre_train = cross_val_predict(clf, train_x, train_y, cv=<span class="number">10</span>)</span><br><span class="line">    <span class="comment"># 获取精准度，召回率还有F1得分</span></span><br><span class="line">    precision = precision_score(train_y, pre_train, average=<span class="string">&#x27;macro&#x27;</span>)</span><br><span class="line">    recall = recall_score(train_y, pre_train, average=<span class="string">&#x27;macro&#x27;</span>)</span><br><span class="line">    F1 = f1_score(train_y, pre_train, average=<span class="string">&#x27;macro&#x27;</span>)</span><br><span class="line">    <span class="keyword">return</span> [mean_score, std_score, precision, recall, F1]</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment"># 梯度提升树</span></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">run_gbdt</span>(<span class="params">train_x, train_y</span>):</span></span><br><span class="line">    clf = GradientBoostingClassifier()</span><br><span class="line">    clf.fit(train_x, train_y)</span><br><span class="line">    <span class="comment"># 10折交叉验证,获取准确率的均值和标准差</span></span><br><span class="line">    scores = cross_val_score(clf, train_x, train_y, scoring=<span class="string">&#x27;accuracy&#x27;</span>, cv=<span class="number">10</span>)</span><br><span class="line">    mean_score = np.array(scores).mean()</span><br><span class="line">    std_score = np.array(scores).std()</span><br><span class="line">    <span class="comment"># 10折交叉验证,获取预测类别</span></span><br><span class="line">    pre_train = cross_val_predict(clf, train_x, train_y, cv=<span class="number">10</span>)</span><br><span class="line">    <span class="comment"># 获取精准度，召回率还有F1得分</span></span><br><span class="line">    precision = precision_score(train_y, pre_train, average=<span class="string">&#x27;macro&#x27;</span>)</span><br><span class="line">    recall = recall_score(train_y, pre_train, average=<span class="string">&#x27;macro&#x27;</span>)</span><br><span class="line">    F1 = f1_score(train_y, pre_train, average=<span class="string">&#x27;macro&#x27;</span>)</span><br><span class="line">    <span class="keyword">return</span> [mean_score, std_score, precision, recall, F1]</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">run_cross</span>(<span class="params">train_x, train_y</span>):</span></span><br><span class="line">    list_lr = run_lr(train_x, train_y)</span><br><span class="line">    list_lsvc = run_linearsvc(train_x, train_y)</span><br><span class="line">    list_sgd = run_sgd(train_x, train_y)</span><br><span class="line">    list_svc = run_svc(train_x, train_y)</span><br><span class="line">    list_tree = run_tree(train_x, train_y)</span><br><span class="line">    list_knn = run_knn(train_x, train_y)</span><br><span class="line">    list_rf = run_rf(train_x, train_y)</span><br><span class="line">    list_gbdt = run_gbdt(train_x, train_y)</span><br><span class="line">    <span class="keyword">return</span> [list_lr, list_lsvc, list_sgd, list_svc, list_tree, list_knn, list_rf, list_gbdt]</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h2 id="调用函数"><a href="#调用函数" class="headerlink" title="调用函数"></a>调用函数</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># -*- coding: utf-8 -*-</span></span><br><span class="line"><span class="comment"># @Time     : 2020/8/31</span></span><br><span class="line"><span class="comment"># @Author   : esy</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> warnings</span><br><span class="line"><span class="keyword">from</span> data_preprocessing <span class="keyword">import</span> *</span><br><span class="line"><span class="keyword">from</span> sklearn.model_selection <span class="keyword">import</span> train_test_split</span><br><span class="line"><span class="keyword">from</span> cross_acr_f1 <span class="keyword">import</span> *</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment"># 忽略警告</span></span><br><span class="line">warnings.filterwarnings(<span class="string">&#x27;ignore&#x27;</span>)</span><br><span class="line"></span><br><span class="line"><span class="comment"># 提取分期为2时的17个特征</span></span><br><span class="line">feature_name = np.array(pd.read_excel(<span class="string">&#x27;F:/st_data/30-17个特征.xlsx&#x27;</span>)[<span class="string">&#x27;stage_2&#x27;</span>])[<span class="number">0</span>:<span class="number">17</span>]</span><br><span class="line"></span><br><span class="line"><span class="comment"># 读取ucddb库中的名字和AHI/SEFF</span></span><br><span class="line">data = pd.read_excel(<span class="string">&#x27;F:/py/py_sleep stage and apnea/data/&#x27;</span> + <span class="string">&#x27;ucddb&#x27;</span> + <span class="string">&#x27;_sleep_stages.xlsx&#x27;</span>)</span><br><span class="line">study_name = np.array(data[<span class="string">&#x27;data&#x27;</span>])</span><br><span class="line">data_AHI = np.array(data[<span class="string">&#x27;AHI&#x27;</span>])</span><br><span class="line">data_seff = np.array(data[<span class="string">&#x27;Seff&#x27;</span>])</span><br><span class="line"></span><br><span class="line"><span class="comment"># 读取ucddb库中的单个数据的全部特征</span></span><br><span class="line"><span class="keyword">for</span> text <span class="keyword">in</span> study_name[<span class="number">0</span>:<span class="number">1</span>]:</span><br><span class="line">    <span class="comment"># 读取ucddb库中的102个特征</span></span><br><span class="line">    features = pd.read_excel(<span class="string">&#x27;E:/MIT data/ucddb_feature/features_&#x27;</span> + <span class="string">&#x27;%s&#x27;</span> % text + <span class="string">&#x27;.xlsx&#x27;</span>)</span><br><span class="line">    <span class="comment"># 将获取的17个特征进行标准化和补缺失值</span></span><br><span class="line">    df = data_pre(pd.get_dummies(features.iloc[:, <span class="number">1</span>:])[feature_name])</span><br><span class="line">    <span class="comment"># 获取标签</span></span><br><span class="line">    labels = pd.read_excel(<span class="string">&#x27;E:/MIT data/ucddb_note/note_&#x27;</span> + <span class="string">&#x27;%s&#x27;</span> % text + <span class="string">&#x27;.xlsx&#x27;</span>)</span><br><span class="line">    tag = pd.get_dummies(labels.iloc[<span class="number">0</span>:<span class="built_in">len</span>(features), <span class="number">1</span>:<span class="number">2</span>])</span><br><span class="line"></span><br><span class="line">    <span class="comment"># 分层抽样并按照7:3划分为训练集和测试集</span></span><br><span class="line">    class_cross = []</span><br><span class="line">    <span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">10</span>):</span><br><span class="line">        X_train, X_test, y_train, y_test = train_test_split(df, tag, stratify=tag, test_size=<span class="number">0.3</span>)</span><br><span class="line">        class_cross.append(run_cross(X_train, y_train))</span><br><span class="line"></span><br><span class="line">    all_class = []</span><br><span class="line">    <span class="keyword">for</span> j <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">8</span>):</span><br><span class="line">        class_1 = []</span><br><span class="line">        <span class="keyword">for</span> k <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">5</span>):</span><br><span class="line">            mean_acr = []</span><br><span class="line">            <span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">10</span>):</span><br><span class="line">                mean_acr.append(class_cross[i][j][k])</span><br><span class="line">            mean_lr = np.array(mean_acr).mean()</span><br><span class="line">            class_1.append(mean_lr)</span><br><span class="line">        all_class.append(class_1)</span><br></pre></td></tr></table></figure>



<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># -*- coding: utf-8 -*-</span></span><br><span class="line"><span class="comment"># @Time     : 2020/8/31</span></span><br><span class="line"><span class="comment"># @Author   : esy</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> warnings</span><br><span class="line"><span class="keyword">from</span> data_preprocessing <span class="keyword">import</span> *</span><br><span class="line"><span class="keyword">from</span> sklearn.model_selection <span class="keyword">import</span> train_test_split</span><br><span class="line"><span class="keyword">from</span> cross_acr_f1 <span class="keyword">import</span> *</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment"># 忽略警告</span></span><br><span class="line">warnings.filterwarnings(<span class="string">&#x27;ignore&#x27;</span>)</span><br><span class="line"></span><br><span class="line"><span class="comment"># 提取分期为2时的17个特征</span></span><br><span class="line">feature_name = np.array(pd.read_excel(<span class="string">&#x27;F:/st_data/30-17个特征.xlsx&#x27;</span>)[<span class="string">&#x27;stage_2&#x27;</span>])[<span class="number">0</span>:<span class="number">17</span>]</span><br><span class="line"></span><br><span class="line"><span class="comment"># 读取ucddb库中的名字和AHI/SEFF</span></span><br><span class="line">data = pd.read_excel(<span class="string">&#x27;F:/py/py_sleep stage and apnea/data/&#x27;</span> + <span class="string">&#x27;ucddb&#x27;</span> + <span class="string">&#x27;_sleep_stages.xlsx&#x27;</span>)</span><br><span class="line">study_name = np.array(data[<span class="string">&#x27;data&#x27;</span>])</span><br><span class="line">data_AHI = np.array(data[<span class="string">&#x27;AHI&#x27;</span>])</span><br><span class="line">data_seff = np.array(data[<span class="string">&#x27;Seff&#x27;</span>])</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">ucddb_class = []</span><br><span class="line"><span class="comment"># 读取ucddb库中的单个数据的全部特征</span></span><br><span class="line"><span class="keyword">for</span> text <span class="keyword">in</span> study_name:</span><br><span class="line">    <span class="comment"># 读取ucddb库中的102个特征</span></span><br><span class="line">    features = pd.read_excel(<span class="string">&#x27;E:/MIT data/ucddb_feature/features_&#x27;</span> + <span class="string">&#x27;%s&#x27;</span> % text + <span class="string">&#x27;.xlsx&#x27;</span>)</span><br><span class="line">    <span class="comment"># 将获取的17个特征进行标准化和补缺失值</span></span><br><span class="line">    df = data_pre(pd.get_dummies(features.iloc[:, <span class="number">1</span>:])[feature_name])</span><br><span class="line">    <span class="comment"># 获取标签</span></span><br><span class="line">    labels = pd.read_excel(<span class="string">&#x27;E:/MIT data/ucddb_note/note_&#x27;</span> + <span class="string">&#x27;%s&#x27;</span> % text + <span class="string">&#x27;.xlsx&#x27;</span>)</span><br><span class="line">    tag = pd.get_dummies(labels.iloc[<span class="number">0</span>:<span class="built_in">len</span>(features), <span class="number">1</span>:<span class="number">2</span>])</span><br><span class="line"></span><br><span class="line">    <span class="comment"># 分层抽样并按照7:3划分为训练集和测试集</span></span><br><span class="line">    class_cross = []</span><br><span class="line">    <span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">10</span>):</span><br><span class="line">        X_train, X_test, y_train, y_test = train_test_split(df, tag, stratify=tag, test_size=<span class="number">0.3</span>)</span><br><span class="line">        class_cross.append(run_cross(X_train, y_train))</span><br><span class="line">    all_class = [[np.array([class_cross[i][j][k] <span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">10</span>)]).mean() <span class="keyword">for</span> k <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">5</span>)] <span class="keyword">for</span> j <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">8</span>)]</span><br><span class="line">    ucddb_class.append(all_class)</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>先保存，然后再重新调用，到时看数据的情况。</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># -*- coding: utf-8 -*-</span></span><br><span class="line"><span class="comment"># @Time     : 2020/9/1</span></span><br><span class="line"><span class="comment"># @Author   : esy</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> pandas <span class="keyword">as</span> pd</span><br><span class="line"><span class="keyword">import</span> numpy <span class="keyword">as</span> np</span><br><span class="line"><span class="keyword">import</span> warnings</span><br><span class="line"></span><br><span class="line">warnings.filterwarnings(<span class="string">&#x27;ignore&#x27;</span>)</span><br><span class="line"></span><br><span class="line"><span class="keyword">for</span> index <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">2</span>, <span class="number">6</span>):</span><br><span class="line">    cross = pd.read_excel(<span class="string">&#x27;E:/交叉验证结果/&#x27;</span> + <span class="string">&#x27;%d&#x27;</span> % index + <span class="string">&#x27;期时的交叉验证结果.xlsx&#x27;</span>)</span><br><span class="line">    mean_all = [[np.array([<span class="built_in">eval</span>(cross[i][j])[k] <span class="keyword">for</span> j <span class="keyword">in</span> <span class="built_in">range</span>(<span class="built_in">len</span>(cross))]).mean() <span class="keyword">for</span> k <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">5</span>)] <span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">8</span>)]</span><br><span class="line"></span><br><span class="line">    data = pd.DataFrame(mean_all, index=[<span class="string">&#x27;lr&#x27;</span>, <span class="string">&#x27;lsvc&#x27;</span>, <span class="string">&#x27;sgd&#x27;</span>, <span class="string">&#x27;svc&#x27;</span>, <span class="string">&#x27;tree&#x27;</span>, <span class="string">&#x27;knn&#x27;</span>, <span class="string">&#x27;rf&#x27;</span>, <span class="string">&#x27;gbdt&#x27;</span>],</span><br><span class="line">                        columns=[<span class="string">&#x27;acr&#x27;</span>, <span class="string">&#x27;std&#x27;</span>, <span class="string">&#x27;precision&#x27;</span>, <span class="string">&#x27;recall&#x27;</span>, <span class="string">&#x27;F1&#x27;</span>])</span><br><span class="line">    data.to_excel(<span class="string">&#x27;cross_acr_stage&#x27;</span> + <span class="string">&#x27;%d&#x27;</span> % index + <span class="string">&#x27;.xlsx&#x27;</span>)</span><br></pre></td></tr></table></figure>

<table>
<thead>
<tr>
<th>stage_2</th>
<th><strong>acr</strong></th>
<th><strong>std</strong></th>
<th><strong>precision</strong></th>
<th><strong>recall</strong></th>
<th><strong>F1</strong></th>
</tr>
</thead>
<tbody><tr>
<td><strong>lr</strong></td>
<td>0.873204</td>
<td>0.03342</td>
<td>0.825375</td>
<td>0.733596</td>
<td>0.759565</td>
</tr>
<tr>
<td><strong>lsvc</strong></td>
<td>0.876835</td>
<td>0.032714</td>
<td>0.838397</td>
<td>0.73677</td>
<td>0.764255</td>
</tr>
<tr>
<td><strong>sgd</strong></td>
<td>0.840779</td>
<td>0.049567</td>
<td>0.747202</td>
<td>0.73014</td>
<td>0.736533</td>
</tr>
<tr>
<td><strong>svc</strong></td>
<td>0.892471</td>
<td>0.029874</td>
<td>0.87406</td>
<td>0.756022</td>
<td>0.786449</td>
</tr>
<tr>
<td><strong>tree</strong></td>
<td>0.879118</td>
<td>0.038455</td>
<td>0.799414</td>
<td>0.79918</td>
<td>0.798938</td>
</tr>
<tr>
<td><strong>knn</strong></td>
<td>0.899159</td>
<td>0.031359</td>
<td>0.8657</td>
<td>0.783775</td>
<td>0.810978</td>
</tr>
<tr>
<td><strong>rf</strong></td>
<td>0.907763</td>
<td>0.030804</td>
<td>0.875697</td>
<td>0.800254</td>
<td>0.827333</td>
</tr>
<tr>
<td><strong>gbdt</strong></td>
<td>0.910328</td>
<td>0.031105</td>
<td>0.867326</td>
<td>0.816129</td>
<td>0.836155</td>
</tr>
</tbody></table>
<table>
<thead>
<tr>
<th>stage_3</th>
<th><strong>acr</strong></th>
<th><strong>std</strong></th>
<th><strong>precision</strong></th>
<th><strong>recall</strong></th>
<th><strong>F1</strong></th>
</tr>
</thead>
<tbody><tr>
<td><strong>lr</strong></td>
<td>0.792084</td>
<td>0.042254</td>
<td>0.728096</td>
<td>0.620623</td>
<td>0.64276</td>
</tr>
<tr>
<td><strong>lsvc</strong></td>
<td>0.802505</td>
<td>0.042456</td>
<td>0.749108</td>
<td>0.644193</td>
<td>0.67019</td>
</tr>
<tr>
<td><strong>sgd</strong></td>
<td>0.764561</td>
<td>0.054607</td>
<td>0.674735</td>
<td>0.637357</td>
<td>0.649782</td>
</tr>
<tr>
<td><strong>svc</strong></td>
<td>0.830053</td>
<td>0.039064</td>
<td>0.805598</td>
<td>0.67005</td>
<td>0.702448</td>
</tr>
<tr>
<td><strong>tree</strong></td>
<td>0.836634</td>
<td>0.044526</td>
<td>0.776706</td>
<td>0.776503</td>
<td>0.775981</td>
</tr>
<tr>
<td><strong>knn</strong></td>
<td>0.853001</td>
<td>0.039173</td>
<td>0.82644</td>
<td>0.749573</td>
<td>0.776256</td>
</tr>
<tr>
<td><strong>rf</strong></td>
<td>0.875021</td>
<td>0.038509</td>
<td>0.857863</td>
<td>0.790371</td>
<td>0.816468</td>
</tr>
<tr>
<td><strong>gbdt</strong></td>
<td>0.883001</td>
<td>0.037505</td>
<td>0.864701</td>
<td>0.806511</td>
<td>0.82958</td>
</tr>
</tbody></table>
<table>
<thead>
<tr>
<th>stage_4</th>
<th><strong>acr</strong></th>
<th><strong>std</strong></th>
<th><strong>precision</strong></th>
<th><strong>recall</strong></th>
<th><strong>F1</strong></th>
</tr>
</thead>
<tbody><tr>
<td><strong>lr</strong></td>
<td>0.721052</td>
<td>0.048301</td>
<td>0.663519</td>
<td>0.571228</td>
<td>0.587809</td>
</tr>
<tr>
<td><strong>lsvc</strong></td>
<td>0.735596</td>
<td>0.046768</td>
<td>0.695477</td>
<td>0.600284</td>
<td>0.621023</td>
</tr>
<tr>
<td><strong>sgd</strong></td>
<td>0.683904</td>
<td>0.059923</td>
<td>0.622163</td>
<td>0.589934</td>
<td>0.599896</td>
</tr>
<tr>
<td><strong>svc</strong></td>
<td>0.77124</td>
<td>0.044369</td>
<td>0.755301</td>
<td>0.628645</td>
<td>0.655689</td>
</tr>
<tr>
<td><strong>tree</strong></td>
<td>0.794947</td>
<td>0.048561</td>
<td>0.759304</td>
<td>0.757206</td>
<td>0.757366</td>
</tr>
<tr>
<td><strong>knn</strong></td>
<td>0.803281</td>
<td>0.046634</td>
<td>0.789236</td>
<td>0.730978</td>
<td>0.750146</td>
</tr>
<tr>
<td><strong>rf</strong></td>
<td>0.843469</td>
<td>0.042679</td>
<td>0.840218</td>
<td>0.785219</td>
<td>0.806853</td>
</tr>
<tr>
<td><strong>gbdt</strong></td>
<td>0.8521</td>
<td>0.04264</td>
<td>0.852484</td>
<td>0.793713</td>
<td>0.817332</td>
</tr>
</tbody></table>
<table>
<thead>
<tr>
<th>stage_5</th>
<th><strong>acr</strong></th>
<th><strong>std</strong></th>
<th><strong>precision</strong></th>
<th><strong>recall</strong></th>
<th><strong>F1</strong></th>
</tr>
</thead>
<tbody><tr>
<td><strong>lr</strong></td>
<td>0.645579</td>
<td>0.049839</td>
<td>0.591382</td>
<td>0.521489</td>
<td>0.525964</td>
</tr>
<tr>
<td><strong>lsvc</strong></td>
<td>0.661358</td>
<td>0.049126</td>
<td>0.612617</td>
<td>0.548897</td>
<td>0.55334</td>
</tr>
<tr>
<td><strong>sgd</strong></td>
<td>0.591087</td>
<td>0.06421</td>
<td>0.539555</td>
<td>0.51574</td>
<td>0.521715</td>
</tr>
<tr>
<td><strong>svc</strong></td>
<td>0.701606</td>
<td>0.048033</td>
<td>0.672929</td>
<td>0.581888</td>
<td>0.595645</td>
</tr>
<tr>
<td><strong>tree</strong></td>
<td>0.739748</td>
<td>0.05237</td>
<td>0.706157</td>
<td>0.705201</td>
<td>0.704886</td>
</tr>
<tr>
<td><strong>knn</strong></td>
<td>0.736938</td>
<td>0.049964</td>
<td>0.716943</td>
<td>0.671462</td>
<td>0.684666</td>
</tr>
<tr>
<td><strong>rf</strong></td>
<td>0.792051</td>
<td>0.046862</td>
<td>0.777754</td>
<td>0.740566</td>
<td>0.754568</td>
</tr>
<tr>
<td><strong>gbdt</strong></td>
<td>0.80258</td>
<td>0.046231</td>
<td>0.793377</td>
<td>0.746552</td>
<td>0.76463</td>
</tr>
</tbody></table>
<p>目的：</p>
<p>标准差为单人标准差下的均值</p>
<p>确定2345期中的最优模型，进行筛选</p>
<p>综合上述4个表格。选择RF和GBDT作为超参数优化。、</p>
<p><img src="https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1598953428509&di=c0a95868d76a72e79cd00e0d87c33d95&imgtype=0&src=http://pic3.zhimg.com/50/v2-407554e0d45f7331456955554be770b2_hd.gif"></p>

    </div>
</article>


                </div>
                <aside class="col-md-4 gal-left" id="sidebar">
    <!-- 此为sidebar的搜索框, 非搜索结果页面 -->
<aside id="sidebar-search">
    <div class="search hidden-xs" data-aos="fade-up" data-aos-duration="2000">
        <form class="form-inline clearfix" id="search-form" method="get"
              action="/search/index.html">
            <input type="text" name="s" class="form-control" id="searchInput" placeholder="搜索文章~" autocomplete="off">
            <button class="btn btn-danger btn-gal" type="submit">
                <i class="fa fa-search"></i>
            </button>
        </form>
    </div>
</aside>
    <aside id="sidebar-author">
    <div class="panel panel-gal" data-aos="flip-right" data-aos-duration="3000">
        <div class="panel-heading" style="text-align: center">
            <i class="fa fa-quote-left"></i>
            esy
            <i class="fa fa-quote-right"></i>
        </div>
        <div class="author-panel text-center">
            <img src="/imgs/avatar.jpg" width="140" height="140"
                 alt="个人头像" class="author-image">
            <p class="author-description"><p>esy</p>
</p>
        </div>
    </div>
</aside>
    
    <aside id="sidebar-recent_comments">
    <div class="panel panel-gal recent hidden-xs" data-aos="fade-up" data-aos-duration="2000">
        <div class="panel-heading">
            <i class="fa fa-comments"></i>
            最新评论
            <i class="fa fa-times-circle panel-remove"></i>
            <i class="fa fa-chevron-circle-up panel-toggle"></i>
        </div>
        <ul class="list-group list-group-flush"></ul>
    </div>
</aside>
    
    <!-- 要配置好leancloud才能开启此小工具 -->
    
    
    <aside id="sidebar-recent_posts">
    <div class="panel panel-gal recent hidden-xs" data-aos="fade-up" data-aos-duration="2000">
        <div class="panel-heading">
            <i class="fa fa-refresh"></i>
            近期文章
            <i class="fa fa-times-circle panel-remove"></i>
            <i class="fa fa-chevron-circle-up panel-toggle"></i>
        </div>
        <ul class="list-group list-group-flush">
            
            <li class="list-group-item">
                <span class="post-title">
                    <a href="/2020/11/05/python%20work/%E6%9C%80%E5%B0%8F%E4%BA%8C%E4%B9%98%E6%B3%95/">最小二乘法</a>
                </span>
            </li>
            
            <li class="list-group-item">
                <span class="post-title">
                    <a href="/2020/11/05/python%20work/%E7%BB%9F%E8%AE%A1%E5%AD%A6%E4%B9%A0-%E7%AC%AC%E4%B8%80%E7%AB%A0/">统计学习--第一章</a>
                </span>
            </li>
            
            <li class="list-group-item">
                <span class="post-title">
                    <a href="/2020/11/04/python%20work/hello-world/">Hello World</a>
                </span>
            </li>
            
            <li class="list-group-item">
                <span class="post-title">
                    <a href="/2020/11/03/python%20work/%E5%88%86%E7%B1%BB%E6%A8%A1%E5%9E%8B%E7%9A%84%E8%AF%84%E4%BC%B0%E6%8C%87%E6%A0%87/">分类模型的评估指标</a>
                </span>
            </li>
            
            <li class="list-group-item">
                <span class="post-title">
                    <a href="/2020/10/21/python%20work/10-21-%E7%88%AC%E8%99%AB%E5%9F%BA%E7%A1%80/">10-21 爬虫基础</a>
                </span>
            </li>
            
            <li class="list-group-item">
                <span class="post-title">
                    <a href="/2020/09/25/python%20work/CRF%E7%9A%84%E6%95%B4%E4%BD%93%E6%B5%81%E7%A8%8B%E7%BB%93%E6%9E%9C/">CRF的整体流程结果</a>
                </span>
            </li>
            
            <li class="list-group-item">
                <span class="post-title">
                    <a href="/2020/09/25/python%20work/nlp-crf%E6%A8%A1%E5%9E%8B/">nlp_crf模型</a>
                </span>
            </li>
            
            <li class="list-group-item">
                <span class="post-title">
                    <a href="/2020/09/25/python%20work/%E6%95%B0%E5%AD%A6%E5%BB%BA%E6%A8%A1%E9%97%AE%E9%A2%983/">数学建模问题3</a>
                </span>
            </li>
            
            <li class="list-group-item">
                <span class="post-title">
                    <a href="/2020/09/25/python%20work/%E6%95%B0%E5%AD%A6%E5%BB%BA%E6%A8%A1%E9%97%AE%E9%A2%982/">数学建模问题2</a>
                </span>
            </li>
            
            <li class="list-group-item">
                <span class="post-title">
                    <a href="/2020/09/25/python%20work/%E6%95%B0%E5%AD%A6%E5%BB%BA%E6%A8%A1%E9%97%AE%E9%A2%981/">数学建模问题1</a>
                </span>
            </li>
            
        </ul>
    </div>
</aside>
    
    
    <aside id="sidebar-rand_posts">
    <div class="panel panel-gal recent hidden-xs" data-aos="fade-up" data-aos-duration="2000">
        <div class="panel-heading">
            <i class="fa fa-refresh"></i>
            随机文章
            <i class="fa fa-times-circle panel-remove"></i>
            <i class="fa fa-chevron-circle-up panel-toggle"></i>
        </div>
        <ul class="list-group list-group-flush">
            
            
            <li class="list-group-item">
                <span class="post-title">
                    <a href="/2020/09/25/python%20work/CRF%E7%9A%84%E6%95%B4%E4%BD%93%E6%B5%81%E7%A8%8B%E7%BB%93%E6%9E%9C/">CRF的整体流程结果</a>
                </span>
            </li>
            
            <li class="list-group-item">
                <span class="post-title">
                    <a href="/2020/07/23/python%20work/gui%E7%95%8C%E9%9D%A2%E6%9A%82%E5%AE%9A%E7%89%88%E5%92%8C%E9%81%87%E5%88%B0%E7%9A%84%E9%97%AE%E9%A2%98/">gui界面暂定版和遇到的问题</a>
                </span>
            </li>
            
            <li class="list-group-item">
                <span class="post-title">
                    <a href="/2019/12/04/python%20work/matlab%E4%B8%AD%E7%9A%84function%E5%87%BD%E6%95%B0/">matlab中的function函数</a>
                </span>
            </li>
            
            <li class="list-group-item">
                <span class="post-title">
                    <a href="/2019/11/24/python%20work/pyhon%E5%9F%BA%E7%A1%80-%E6%A8%A1%E5%9D%97/">pyhon基础--模块</a>
                </span>
            </li>
            
            <li class="list-group-item">
                <span class="post-title">
                    <a href="/2020/03/21/python%20work/python-%E6%96%87%E4%BB%B6%E5%AD%98%E5%8F%96%E6%93%8D%E4%BD%9C/">python_文件存取操作</a>
                </span>
            </li>
            
            <li class="list-group-item">
                <span class="post-title">
                    <a href="/2020/06/11/python%20work/%E5%85%A8%E9%83%A8%E7%89%B9%E5%BE%81%E7%9A%84%E6%8F%90%E5%8F%96%E5%92%8C%E6%A0%87%E7%AD%BE%E5%A4%84%E7%90%86/">全部特征的提取和标签处理</a>
                </span>
            </li>
            
            <li class="list-group-item">
                <span class="post-title">
                    <a href="/2020/08/19/python%20work/%E5%A4%84%E7%90%86%E5%B9%B6%E7%BB%9F%E8%AE%A1%E4%B8%A4%E4%B8%AA%E6%95%B0%E6%8D%AE%E5%BA%93%E4%B8%AD%E7%9A%84%E7%9D%A1%E7%9C%A0%E6%A0%87%E7%AD%BE/">处理并统计两个数据库中的睡眠标签</a>
                </span>
            </li>
            
            <li class="list-group-item">
                <span class="post-title">
                    <a href="/2019/12/16/python%20work/%E5%BF%83%E7%8E%87%E5%8F%98%E5%BC%82%E6%80%A7/">心率变异性</a>
                </span>
            </li>
            
            <li class="list-group-item">
                <span class="post-title">
                    <a href="/2020/09/25/python%20work/%E6%95%B0%E5%AD%A6%E5%BB%BA%E6%A8%A1%E9%97%AE%E9%A2%981/">数学建模问题1</a>
                </span>
            </li>
            
            <li class="list-group-item">
                <span class="post-title">
                    <a href="/2020/07/09/python%20work/HMM%E4%B9%8B%E6%95%B0%E6%8D%AE%E7%9A%84%E5%A4%84%E7%90%86/">HMM之数据的处理</a>
                </span>
            </li>
            
        </ul>
    </div>
</aside>
    
    
    <aside id="gal-sets">
        <div class="panel panel-gal hidden-xs" data-aos="fade-up" data-aos-duration="2000">
            <ul class="nav nav-pills pills-gal">

                
                <li>
                    <a href="/2020/08/31/python%20work/%E5%88%86%E7%B1%BB%E6%A8%A1%E5%9E%8B%E5%9F%BA%E4%BA%8E%E4%BA%A4%E5%8F%89%E9%AA%8C%E8%AF%81%E8%BF%9B%E8%A1%8C%E8%AF%84%E4%BC%B0/index.html#sidebar-tags" data-toggle="tab" id="tags-tab">热门标签</a>
                </li>
                
                
                <li>
                    <a href="/2020/08/31/python%20work/%E5%88%86%E7%B1%BB%E6%A8%A1%E5%9E%8B%E5%9F%BA%E4%BA%8E%E4%BA%A4%E5%8F%89%E9%AA%8C%E8%AF%81%E8%BF%9B%E8%A1%8C%E8%AF%84%E4%BC%B0/index.html#sidebar-friend-links" data-toggle="tab" id="friend-links-tab">友情链接</a>
                </li>
                
                
                <li>
                    <a href="/2020/08/31/python%20work/%E5%88%86%E7%B1%BB%E6%A8%A1%E5%9E%8B%E5%9F%BA%E4%BA%8E%E4%BA%A4%E5%8F%89%E9%AA%8C%E8%AF%81%E8%BF%9B%E8%A1%8C%E8%AF%84%E4%BC%B0/index.html#sidebar-links" data-toggle="tab" id="links-tab">个人链接</a>
                </li>
                
            </ul>
            <div class="tab-content">
                
                <div class="cloud-tags tab-pane nav bs-sidenav fade" id="sidebar-tags">
    
    <a href="/tags/py-study/" style="font-size: 12.780372922786334px;" class="tag-cloud-link">py_study</a>
    
    <a href="/tags/nlp/" style="font-size: 14.787290130018938px;" class="tag-cloud-link">nlp</a>
    
    <a href="/tags/Graduation-work/" style="font-size: 12.895252630313546px;" class="tag-cloud-link">Graduation work</a>
    
    <a href="/tags/work/" style="font-size: 14.428022542142367px;" class="tag-cloud-link">work</a>
    
    <a href="/tags/hexo/" style="font-size: 8.117094355752151px;" class="tag-cloud-link">hexo</a>
    
    <a href="/tags/%E4%B8%AA%E4%BA%BA%E5%8D%9A%E5%AE%A2%E6%90%AD%E5%BB%BA/" style="font-size: 13.398763137582659px;" class="tag-cloud-link">-个人博客搭建</a>
    
    <a href="/tags/malab-%E6%AF%95%E4%B8%9A/" style="font-size: 15.73891090767448px;" class="tag-cloud-link">-malab -毕业</a>
    
    <a href="/tags/python-%E4%BA%BA%E5%B7%A5%E6%99%BA%E8%83%BD/" style="font-size: 13.761361611230102px;" class="tag-cloud-link">-python -人工智能</a>
    
    <a href="/tags/python/" style="font-size: 12.407136212789686px;" class="tag-cloud-link">python</a>
    
    <a href="/tags/python/" style="font-size: 9.840441724384693px;" class="tag-cloud-link">-python</a>
    
    <a href="/tags/mathematical-modeling/" style="font-size: 10.06676912298272px;" class="tag-cloud-link">mathematical modeling</a>
    
    <a href="/tags/statistical-learning/" style="font-size: 14.260090672477423px;" class="tag-cloud-link">statistical learning</a>
    
</div>
                
                
                <div class="friend-links tab-pane nav bs-sidenav fade" id="sidebar-friend-links">
    
    <li>
        <a href="http://kdays.net/days/" target="_blank">KDays Forum</a>
    </li>
    
    <li>
        <a href="http://www.gal123.com/" target="_blank">绅士导航♂</a>
    </li>
    
    <li>
        <a href="http://www.moe123.com/" target="_blank">萌导航</a>
    </li>
    
</div>
                
                
                <div class="links tab-pane nav bs-sidenav fade" id="sidebar-links">
    
    <li>
        <a href="https://github.com/ZEROKISEKI/" target="_blank">Github</a>
    </li>
    
    <li>
        <a href="https://coding.net/u/SORA1" target="_blank">Coding</a>
    </li>
    
    <li>
        <a href="https://www.zhihu.com/people/aonosora/activities" target="_blank">知乎</a>
    </li>
    
</div>
                
            </div>
        </div>
    </aside>
    
</aside>
            </div>
        </div>
    </div>
    <footer id="gal-footer">
    <div class="container">
        Copyright © 2018 esy Powered by <a href="https://hexo.io/" target="_blank">Hexo</a>.&nbsp;Theme by <a href="https://github.com/ZEROKISEKI" target="_blank">AONOSORA</a>
    </div>
</footer>

<!-- 回到顶端 -->
<div id="gal-gotop">
    <i class="fa fa-angle-up"></i>
</div>
</body>

<script src="/js/activate-power-mode.js"></script>

<script>

    // 配置highslide
	hs.graphicsDir = '/js/highslide/graphics/'
    hs.outlineType = "rounded-white";
    hs.dimmingOpacity = 0.8;
    hs.outlineWhileAnimating = true;
    hs.showCredits = false;
    hs.captionEval = "this.thumb.alt";
    hs.numberPosition = "caption";
    hs.align = "center";
    hs.transitions = ["expand", "crossfade"];
    hs.lang.number = '共%2张图, 当前是第%1张';
    hs.addSlideshow({
      interval: 5000,
      repeat: true,
      useControls: true,
      fixedControls: "fit",
      overlayOptions: {
        opacity: 0.75,
        position: "bottom center",
        hideOnMouseOut: true
      }
    })

    // 初始化aos
    AOS.init({
      duration: 1000,
      delay: 0,
      easing: 'ease-out-back'
    });

</script>
<script>
	POWERMODE.colorful = 'true';    // make power mode colorful
	POWERMODE.shake = 'true';       // turn off shake
	// TODO 这里根据具体情况修改
	document.body.addEventListener('input', POWERMODE);
</script>
<script>
    window.slideConfig = {
      prefix: '/imgs/slide/background',
      ext: 'jpg',
      maxCount: '6'
    }
</script>

<script src="/js/hs.js"></script>
<script src="/js/blog.js"></script>



<script src="/js/oni.js"></script>




</html>